import React from "react";
import {message, Modal} from "antd"
import {ProForm, ProFormSelect, ProFormText} from "@ant-design/pro-components";
import {userUpdatePwd} from "@/services/userService";


interface Props {
    modalVisible: boolean;
    onClose: () => void;
}


const updatePassword = async (fileds:UserType.PasswordUpdateRequest)=>{
    await userUpdatePwd(fileds).then(res=>{
        if (res.data===true)
            message.success("更新成功")
    }).catch(e=>{
        message.error(e.message)
    })
}

/**
 * 展示用户信息
 * @param props
 * @constructor
 */
const PwdUpdateModal: React.FC<Props> = (props) => {
    const {modalVisible, onClose} = props

    return (
        <Modal
            title= "更改密码"
            visible={modalVisible}
            onCancel={onClose}
            footer={null}
        >
            <ProForm<UserType.PasswordUpdateRequest>
                onFinish={async (values) => {
                    await updatePassword(values)
                }}
                onReset={onClose}
                submitter={
                    {
                        // 配置按钮文本
                        searchConfig: {
                            submitText: '提交',
                            resetText: '返回',
                        },
                    }
                }
            >
                <ProFormText.Password
                    label="原密码"
                    name="userPassword"
                    placeholder="请输入原来的密码"
                    rules={[{ required: true, message: '必填项' }]}
                />
                <ProFormText.Password
                    label="新密码"
                    name="newPassword"
                    placeholder="请输入新密码"
                    rules={[{ required: true, message: '必填项' }]}
                />
                <ProFormText.Password
                    label="再次输入密码"
                    name="checkPassword"
                    placeholder="请再次输入新密码"
                    rules={[{ required: true, message: '必填项' }]}
                />
            </ProForm>
        </Modal>
    )
}
export default PwdUpdateModal;